﻿@model List<WebEntities.Models.ProductInfo.RecomProduct>

@{
    ViewBag.Title = "网站管理平台_推荐产品管理视图";
}

@section HeadContent
{
    <script type="text/javascript">
        var renderArea = function (value) {
            var result = "";
            switch (value) {
                case "indexarea1":
                    result = "首页产品1";
                    break;
                case "indexarea2":
                    result = "首页产品2";
                    break;
                default:
                    break;
            }
            return result;
        }
    </script>
}

@(Html.X().Menu()
    .ID("Grid1CtxMenu")
    .Items(
        Html.X().MenuItem().Text("删除推荐产品").Icon(Icon.Cross).Listeners(ls => ls.Click.Handler = "App.BtnDeleteSel.getEl().dom.click()")
    )
)

@Html.X().Hidden().ID("DeleteHint").Text("是否要删除选中的推荐产品？")

@(Html.X().Viewport()
        .Layout("fit")
        .Items(
            Html.X().GridPanel()
                .ID("GridPanel1")
                    .Title("推荐产品管理视图")
                .Store(
                    Html.X().StoreForModel()
                        .AutoSync(true)
                        .PageSize(50)
                        .ShowWarningOnFailure(false)
                        .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                            .Url(Url.Action("GetAllRecomProduct"))
                            .Reader(Html.X().JsonReader().Root("data"))
                            .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                            .API(api => { api.Destroy = Url.Action("DeleteRecomProduct"); })
                        ))
                        .Listeners(ls => ls.Write.Fn = "ext.net.comjs.onGridChange")
                )
                .ColumnModel(
                    Html.X().RowNumbererColumn(),
                    Html.X().Column().DataIndex(Model, m => m.ProductName).Text("产品名称"),
                    Html.X().Column().DataIndex(Model, m => m.SortNum).Text("序号")
                    //Html.X().Column().DataIndex(Model, m => m.IndexArea).Text("显示区域").Renderer("renderArea")
                 )
                .SelectionModel(Html.X().CheckboxSelectionModel().Mode(SelectionMode.Multi))
                .Listeners(ls =>
                {
                    ls.ItemContextMenu.Handler = "e.preventDefault(); App.Grid1CtxMenu.dataRecord = this.store.getAt(index); App.Grid1CtxMenu.showAt(e.getXY());";
                })
                .View(Html.X().GridView().StripeRows(true))
                .TopBar(
                    Html.X().Toolbar()
                        .Items(
                            Html.X().Button().Text("新建推荐产品").Icon(Icon.Add).DirectClickAction("NewRecomProductWindow"),
                            Html.X().Button().ID("BtnDeleteSel").Text("删除推荐产品").Icon(Icon.Cross)
                                .Listeners(
                                    ls => ls.Click.Fn = "ext.net.comjs.deleteGridSelected"
                                )
                        )
                )
                .BottomBar(
                    Html.X().PagingToolbar()
                        .Items(
                            Html.X().Label("每页显示行数："),
                            Html.X().ToolbarSpacer(10),
                            Html.X().ComboBox()
                                .Width(80)
                                .Items("10", "50", "100")
                                .SelectedItems("50")
                                .Listeners(lr =>
                                {
                                    lr.Select.Fn = "ext.net.comjs.onPageSizeChange";
                                })
                        )
                )
        )
)